//
//  UIAlertController+Authorization.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/28.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "UIAlertController+Authorization.h"

@implementation UIAlertController (Authorization)


//相册
+ (void)showPhotoAuthorizationWithController:(UIViewController *)prentingController {
    if (!prentingController) {
        return;
    }
    WEAK_SELF
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:BCLocalizedKey(@"tip_alert") message:BCLocalizedFormatString(@"tipTextWhenNoPhotosAuthorization",BCLocalizedKey(@"CFBundleDisplayName")) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:BCLocalizedKey(@"general_cancel") style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *setting = [UIAlertAction actionWithTitle:BCLocalizedKey(@"general_setting") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [wself toSetting];
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:setting];
    [prentingController presentViewController:alertVC animated:true completion:nil];
}

//相机
+ (void)showCameraAuthorizationWithController:(UIViewController *)prentingController {
    if (!prentingController) {
        return;
    }
    WEAK_SELF
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:BCLocalizedKey(@"tip_alert") message:BCLocalizedFormatString(@"tipTextWhenNoCameraAuthorization",BCLocalizedKey(@"CFBundleDisplayName")) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:BCLocalizedKey(@"general_cancel") style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *setting = [UIAlertAction actionWithTitle:BCLocalizedKey(@"general_setting") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [wself toSetting];
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:setting];
    [prentingController presentViewController:alertVC animated:true completion:nil];
}


//去设置
+ (void)toSetting {
    NSURL *settingURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:settingURL]) {
        if (@available(iOS 10.0,*)) {
            [[UIApplication sharedApplication] openURL:settingURL options:@{} completionHandler:nil];
        }else {
            [[UIApplication sharedApplication] openURL:settingURL];
        }
    }
}

@end
